package net.hnjdzy.fengyl.mycontracer.service;

import com.alibaba.fastjson.JSON;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import net.hnjdzy.fengyl.mycontracer.entity.Root;

import java.io.IOException;

public class ConDataManager {
    public static Root root;

    public Root getData()throws Exception{
        OkHttpClient client=new OkHttpClient();
        String url="https://interface.sina.cn/news/wap/fymap2020_data.d.json";
        Request request=new Request.Builder().url(url).build();
        Response response=client.newCall(request).execute();
        if (response.isSuccessful()){
            String json=response.body().string();
            return JSON.parseObject(json,Root.class);
        }else{
            throw new IOException("Unexpected code"+response);
        }
    }
}
